package com.example.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.server.bean.AdminRole;
import com.example.server.util.RespBean;
import com.example.server.dao.AdminRoleDao;
import com.example.server.service.IAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 别怿言
 * @since 2023-02-03
 */
@Service
@Transactional
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleDao, AdminRole> implements IAdminRoleService {

    @Autowired
    private AdminRoleDao adminRoleDao;

    @Override
    public RespBean updateRole(Integer adminId, Integer[] ids) {
        adminRoleDao.delete(new QueryWrapper<AdminRole>().eq("adminId",adminId));
        int result = adminRoleDao.addAdminRole(adminId,ids);
        if(result == ids.length){
            return RespBean.success("修改角色信息成功！");
        }
        return RespBean.error("修改角色信息失败！");
    }
}
